package com.sms.service.impl;

import com.sms.util.SqlSessionFactoryUtil;
import lombok.Getter;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sms.mapper.UsersMapper;
import com.sms.pojo.Users;
import com.sms.service.UsersService;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

@Getter
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {

    private SqlSession sqlSession;
    @Override
    public UsersMapper getBaseMapper() {
        SqlSessionFactory factory = SqlSessionFactoryUtil.getFactory();
        sqlSession=factory.openSession(true);
        UsersMapper mapper = factory.getConfiguration().getMapper(UsersMapper.class, sqlSession);
        return mapper;
    }

    @Override
    public Users findByUsernameAndPassword(String username, String password) {
        return this.getBaseMapper().findByUsernameAndPassword(username, password);
    }

    public boolean modifyPassword(String username, String password){
        Users pduser = findByUsernameAndPassword(username,password);
        return pduser!=null;
    }


    public boolean login(Users user) {
        Users foundUser = findByUsernameAndPassword(user.getUsername(), user.getPassword());
        return foundUser != null;
    }
}
